package com.imooc.bilibili.service;

import com.imooc.bilibili.dao.UserRoleDao;
import com.imooc.bilibili.domain.auth.AuthRole;
import com.imooc.bilibili.domain.auth.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserRoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    /**
     * 获取用户的角色列表
     * @param userId
     * @return
     */
    public List<UserRole> getUserRoleByUserId(Long userId) {
        List<UserRole> userRoleList = userRoleDao.getUserRoleByUserId(userId);
        return userRoleList;
    }

    /**
     * 通过编码获取用户角色
     * @param roleLv0
     * @return
     */
    public AuthRole getRoleByCode(String roleLv0) {
        return userRoleDao.getRoleByCode(roleLv0);
    }

    /**
     * 添加用户角色信息
     * @param userRole
     */
    public void addUserRole(UserRole userRole) {
        userRole.setCreateTime(new Date());
        userRoleDao.addUserRole(userRole);
    }
}
